package com.corpgovernment.organization.controller;

import com.corpgovernment.api.organization.model.user.Clear12306RequestBo;
import com.corpgovernment.api.organization.model.user.Find12306RequestBo;
import com.corpgovernment.api.organization.model.user.Save12306RequestBo;
import com.corpgovernment.api.organization.model.user.Update12306RequestBo;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.organization.entity.db.User12306Relation;
import com.corpgovernment.organization.service.IUser12306RelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户12306关联关系controller
 *
 * @author wangyujue
 */
@RestController
@RequestMapping("/12306")
public class User12306RelationController {

	@Autowired
	private IUser12306RelationService user12306RelationService;

	/**
	 * 保存用户12306账号
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveUser12306Account")
	@ResponseBody
	public JSONResult<Boolean> saveUser12306Account(@RequestBody Save12306RequestBo request) {
		boolean b = user12306RelationService.saveUser12306Account(request.getUid(), request.getAccount(), request.getSupplierCode(), request.getAccountPwd());
		return JSONResult.success(b);
	}

	/**
	 * 修改用户12306账号
	 *
	 * @param request 12306账号
	 * @return
	 */
	@RequestMapping("/updateUser12306Account")
	@ResponseBody
	public JSONResult<Boolean> updateUser12306Account(@RequestBody Update12306RequestBo request) {
		boolean b = user12306RelationService.updateUser12306Account(request.getUid(), request.getAccount());
		return JSONResult.success(b);
	}

	/**
	 * 清除用户12306账号
	 *
	 * @param request 用户id
	 * @return
	 */
	@RequestMapping("/clearUser12306Account")
	@ResponseBody
	public JSONResult<Boolean> clearUser12306Account(@RequestBody Clear12306RequestBo request) {
		boolean b = user12306RelationService.clearUser12306Account(request.getUid(), request.getSupplierCode());
		return JSONResult.success(b);
	}

	/**
	 * 查询用户12306账号
     *
     * @param request     用户id
     * @return
     */
    @RequestMapping("/findUser12306Account")
    @ResponseBody
    public JSONResult<User12306Relation> findUser12306Account(@RequestBody Find12306RequestBo request) {
		User12306Relation user12306Account = user12306RelationService.findUser12306Account(request);
		return JSONResult.success(user12306Account);
    }
}
